﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>隐藏不想打印的页面内容</title>
    <script type="text/javascript" language="JavaScript">
        function preview(){
            // 获取页面内容
            var bdhtml = document.body.innerHTML;
            var beginstr="<!--startprint-->";
            var endstr="<!--endprint-->";
            //获取要打印的内容
            var prnhtml = bdhtml.substring(bdhtml.indexOf(beginstr) + 17);
            prnhtml = prnhtml.substring(0,prnhtml.indexOf(endstr));
            // 预览
            window.document.body.innerHTML = prnhtml;
            // 打印
            window.print();
        }

    </script>
</head>
<body background="" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" style="background-position: center 50%">
<div align=center>
    <span>这里是我需要的内容</span>..........
</div>
<!--endprint-->
<div align="center">
    <span>这里不是我要的内容</span><br />
    <input type="button" value="打印" onclick="preview()" />
</div>

</body>
</html>